package com.example.hm_dtfkz.ui.adapter;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.example.hm_dtfkz.R;
import com.example.hm_dtfkz.entity.BillTypeEntity;
import com.example.hm_dtfkz.util.ActivityClickUtil;


/**
 * FileName: HomeRunAdapter
 * Author: admin
 * Date: 2021/11/5 14:07
 * Description:
 */
public class BillRunAdapter extends BaseQuickAdapter<BillTypeEntity, BaseViewHolder> {

    private OnItemClickLister clickLister;
    private OnGuideLister guideLister;
    private int rightIndex = -1;

    public BillRunAdapter() {
        super(R.layout.item_bill_run);
    }

    @Override
    protected int getDefItemViewType(int position) {
        return position;
    }

    @Override
    protected void convert(@NonNull BaseViewHolder baseViewHolder, BillTypeEntity data) {
        Context context = getContext();
        final int pos = getItemPosition(data);

        ImageView imageview = baseViewHolder.getView(R.id.imageview);
        ImageView img = baseViewHolder.getView(R.id.img);
        TextView tvType = baseViewHolder.getView(R.id.tvType);
        TextView tvName = baseViewHolder.getView(R.id.tvName);

        Glide.with(imageview)
                .load(data.getCover())
                .placeholder(R.drawable.ic_invite_panel_2)
                .error(R.drawable.ic_invite_panel_2)
                .into(imageview);
        if (pos % 2 == 1) {
            Glide.with(img)
                    .load("https://img2.baidu.com/it/u=1893171979,2260795920&fm=253&fmt=auto&app=120&f=JPEG?w=506&h=500")
                    .placeholder(R.drawable.icon_help_receive_header)
                    .error(R.drawable.icon_help_receive_header)
                    .into(img);
        } else {
            Glide.with(img)
                    .load("https://wx4.sinaimg.cn/mw690/0066T9L8gy1hqiysl7o2nj30u00u076x.jpg")
                    .placeholder(R.drawable.icon_help_send_header)
                    .error(R.drawable.icon_help_send_header)
                    .into(img);

        }
        tvName.setText(data.getName());

        tvType.setText(data.getName());
        imageview.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                DQLog.e("answer option: " + tvAnswer.getText().toString());
//                DQLog.e("tvAnswer clicked");
                if (ActivityClickUtil.getInstance().isFastClick()) {
                    //防止用户快速点击
                    return;
                }
//                DQLog.e("tvAnswer onItemClick");
                if (clickLister != null) {
                    clickLister.onItemClick(pos, imageview);
                }
            }
        });


    }

    public void setOnItemClickLister(OnItemClickLister lister) {
        this.clickLister = lister;
    }

    public void setGuideLister(OnGuideLister lister) {
        this.guideLister = lister;
    }

    public void setRightIndex(int index) {
        this.rightIndex = index;
    }

    public interface OnItemClickLister {
        void onItemClick(int position, ImageView tvAnswer);
    }

    public interface OnGuideLister {
        void onGuideView(int position, ImageView tvAnswer);
    }
}
